# Maintainer: Oscar Fuentes <ofv@wanadoo.es>

_realname=tclx
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_majorminor=8.4
pkgver=${_majorminor}.1
pkgrel=3
pkgdesc="Extends Tcl by providing new operating system interface commands, extended file control and many other."
arch=('any')
url="http://tclx.sourceforge.net/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-tcl")
source=("https://sourceforge.net/projects/tclx/files/TclX/${pkgver}/${_realname}${pkgver}.tar.bz2"
	'001-fix-detect-mingw.patch'
        'random.c')
sha256sums=('a9b41f606ec6c1268b9c78512e6e1cb533bd9ae3e786e650d111fc16ffe758ec'
            'a60e0f9d5298fcb94843bbbebf428b158171ce9143f3931d12d20ec3689cb25a'
            '32b1b0685d67f20d8f7943682d16caaa86915937f745471652835239af51750c')

prepare() {
    local dst=${srcdir}/${_realname}${_majorminor}/compat
    mkdir -p ${dst}
    cp random.c ${dst}

    cd ${srcdir}/${_realname}${_majorminor}
    patch -p1 -i ${srcdir}/001-fix-detect-mingw.patch
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  [[ "${MINGW_CHOST}" = 'x86_64-w64-mingw32' ]] && enable64bit='--enable-64bit'

  CFLAGS="-DUSE_INTERP_ERRORLINE $CFLAGS" \
  ../${_realname}${_majorminor}/configure \
    --prefix=${MINGW_PREFIX} \
    $enable64bit
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install

  local licdir=${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  mkdir -p ${licdir}
  cp "${srcdir}"/${_realname}${_majorminor}/license.terms ${licdir}
}
